package IOperation;

import Book.BookList;

import java.util.Scanner;

public class borrowOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        System.out.println("借书");
        System.out.println("请输入想借的书名：");
        Scanner scanner = new Scanner(System.in);
        String name =scanner.nextLine();

        // 1.判断是否存在这本书，以及是否已经被借阅
        for (int i = 0; i < bookList.getBookSize(); i++) {
            if(bookList.getBook(i).getName().equals(name)){
                if (!bookList.getBook(i).isBorrowed()) {
                    bookList.getBook(i).setBorrowed(true);
                    System.out.println("成功借走该书");
                    break;
                }
                else{
                    System.out.println("借书失败，书已经被借走了");
                    break;
                 }
            }
        }
    }
}
